﻿// ***********************************************************************
// Project          : Micua
// Assembly         : Micua.Core
// Author           : iceStone
// Created          : 2014-01-05 11:27
// 
// Last Modified By : iceStone
// Last Modified On : 2014-01-11 15:51
// ***********************************************************************
// <copyright file="Convert.cs" company="Wedn.Net">
//     Copyright (c) Wedn.Net. All rights reserved.
// </copyright>
// <summary>获取各种类型的设置信息</summary>
// ***********************************************************************
using System;

namespace Micua.Core.Configuration
{
    /// <summary>
    /// 获取各种类型的设置信息
    /// </summary>
    public static partial class Setting
    {

		#region 获取Boolean类型配置信息值 +static bool GetBoolean(string key, bool def = default(Boolean))
        /// <summary>
        /// 获取Boolean类型配置信息值
        /// </summary>
        /// <remarks>
        ///  2013-11-23 14:27 Created By iceStone
        /// </remarks>
        /// <param name="key">设置键</param>
        /// <param name="def">缺省值</param>
        /// <returns>设置值</returns>
        public static bool GetBoolean(string key, bool def = default(Boolean))
        {
            var res = GetString(key);
            if (res.Length == 0) return def;
            Boolean.TryParse(res, out def);
            return def;
        } 
        #endregion

		#region 获取Char类型配置信息值 +static char GetChar(string key, char def = default(Char))
        /// <summary>
        /// 获取Char类型配置信息值
        /// </summary>
        /// <remarks>
        ///  2013-11-23 14:27 Created By iceStone
        /// </remarks>
        /// <param name="key">设置键</param>
        /// <param name="def">缺省值</param>
        /// <returns>设置值</returns>
        public static char GetChar(string key, char def = default(Char))
        {
            var res = GetString(key);
            if (res.Length == 0) return def;
            Char.TryParse(res, out def);
            return def;
        } 
        #endregion

		#region 获取Decimal类型配置信息值 +static decimal GetDecimal(string key, decimal def = default(Decimal))
        /// <summary>
        /// 获取Decimal类型配置信息值
        /// </summary>
        /// <remarks>
        ///  2013-11-23 14:27 Created By iceStone
        /// </remarks>
        /// <param name="key">设置键</param>
        /// <param name="def">缺省值</param>
        /// <returns>设置值</returns>
        public static decimal GetDecimal(string key, decimal def = default(Decimal))
        {
            var res = GetString(key);
            if (res.Length == 0) return def;
            Decimal.TryParse(res, out def);
            return def;
        } 
        #endregion

		#region 获取Double类型配置信息值 +static double GetDouble(string key, double def = default(Double))
        /// <summary>
        /// 获取Double类型配置信息值
        /// </summary>
        /// <remarks>
        ///  2013-11-23 14:27 Created By iceStone
        /// </remarks>
        /// <param name="key">设置键</param>
        /// <param name="def">缺省值</param>
        /// <returns>设置值</returns>
        public static double GetDouble(string key, double def = default(Double))
        {
            var res = GetString(key);
            if (res.Length == 0) return def;
            Double.TryParse(res, out def);
            return def;
        } 
        #endregion

		#region 获取Single类型配置信息值 +static float GetSingle(string key, float def = default(Single))
        /// <summary>
        /// 获取Single类型配置信息值
        /// </summary>
        /// <remarks>
        ///  2013-11-23 14:27 Created By iceStone
        /// </remarks>
        /// <param name="key">设置键</param>
        /// <param name="def">缺省值</param>
        /// <returns>设置值</returns>
        public static float GetSingle(string key, float def = default(Single))
        {
            var res = GetString(key);
            if (res.Length == 0) return def;
            Single.TryParse(res, out def);
            return def;
        } 
        #endregion

		#region 获取Byte类型配置信息值 +static byte GetByte(string key, byte def = default(Byte))
        /// <summary>
        /// 获取Byte类型配置信息值
        /// </summary>
        /// <remarks>
        ///  2013-11-23 14:27 Created By iceStone
        /// </remarks>
        /// <param name="key">设置键</param>
        /// <param name="def">缺省值</param>
        /// <returns>设置值</returns>
        public static byte GetByte(string key, byte def = default(Byte))
        {
            var res = GetString(key);
            if (res.Length == 0) return def;
            Byte.TryParse(res, out def);
            return def;
        } 
        #endregion

		#region 获取SByte类型配置信息值 +static sbyte GetSByte(string key, sbyte def = default(SByte))
        /// <summary>
        /// 获取SByte类型配置信息值
        /// </summary>
        /// <remarks>
        ///  2013-11-23 14:27 Created By iceStone
        /// </remarks>
        /// <param name="key">设置键</param>
        /// <param name="def">缺省值</param>
        /// <returns>设置值</returns>
        public static sbyte GetSByte(string key, sbyte def = default(SByte))
        {
            var res = GetString(key);
            if (res.Length == 0) return def;
            SByte.TryParse(res, out def);
            return def;
        } 
        #endregion

		#region 获取Int16类型配置信息值 +static short GetInt16(string key, short def = default(Int16))
        /// <summary>
        /// 获取Int16类型配置信息值
        /// </summary>
        /// <remarks>
        ///  2013-11-23 14:27 Created By iceStone
        /// </remarks>
        /// <param name="key">设置键</param>
        /// <param name="def">缺省值</param>
        /// <returns>设置值</returns>
        public static short GetInt16(string key, short def = default(Int16))
        {
            var res = GetString(key);
            if (res.Length == 0) return def;
            Int16.TryParse(res, out def);
            return def;
        } 
        #endregion

		#region 获取UInt16类型配置信息值 +static ushort GetUInt16(string key, ushort def = default(UInt16))
        /// <summary>
        /// 获取UInt16类型配置信息值
        /// </summary>
        /// <remarks>
        ///  2013-11-23 14:27 Created By iceStone
        /// </remarks>
        /// <param name="key">设置键</param>
        /// <param name="def">缺省值</param>
        /// <returns>设置值</returns>
        public static ushort GetUInt16(string key, ushort def = default(UInt16))
        {
            var res = GetString(key);
            if (res.Length == 0) return def;
            UInt16.TryParse(res, out def);
            return def;
        } 
        #endregion

		#region 获取Int32类型配置信息值 +static int GetInt32(string key, int def = default(Int32))
        /// <summary>
        /// 获取Int32类型配置信息值
        /// </summary>
        /// <remarks>
        ///  2013-11-23 14:27 Created By iceStone
        /// </remarks>
        /// <param name="key">设置键</param>
        /// <param name="def">缺省值</param>
        /// <returns>设置值</returns>
        public static int GetInt32(string key, int def = default(Int32))
        {
            var res = GetString(key);
            if (res.Length == 0) return def;
            Int32.TryParse(res, out def);
            return def;
        } 
        #endregion

		#region 获取UInt32类型配置信息值 +static uint GetUInt32(string key, uint def = default(UInt32))
        /// <summary>
        /// 获取UInt32类型配置信息值
        /// </summary>
        /// <remarks>
        ///  2013-11-23 14:27 Created By iceStone
        /// </remarks>
        /// <param name="key">设置键</param>
        /// <param name="def">缺省值</param>
        /// <returns>设置值</returns>
        public static uint GetUInt32(string key, uint def = default(UInt32))
        {
            var res = GetString(key);
            if (res.Length == 0) return def;
            UInt32.TryParse(res, out def);
            return def;
        } 
        #endregion

		#region 获取Int64类型配置信息值 +static long GetInt64(string key, long def = default(Int64))
        /// <summary>
        /// 获取Int64类型配置信息值
        /// </summary>
        /// <remarks>
        ///  2013-11-23 14:27 Created By iceStone
        /// </remarks>
        /// <param name="key">设置键</param>
        /// <param name="def">缺省值</param>
        /// <returns>设置值</returns>
        public static long GetInt64(string key, long def = default(Int64))
        {
            var res = GetString(key);
            if (res.Length == 0) return def;
            Int64.TryParse(res, out def);
            return def;
        } 
        #endregion

		#region 获取UInt64类型配置信息值 +static ulong GetUInt64(string key, ulong def = default(UInt64))
        /// <summary>
        /// 获取UInt64类型配置信息值
        /// </summary>
        /// <remarks>
        ///  2013-11-23 14:27 Created By iceStone
        /// </remarks>
        /// <param name="key">设置键</param>
        /// <param name="def">缺省值</param>
        /// <returns>设置值</returns>
        public static ulong GetUInt64(string key, ulong def = default(UInt64))
        {
            var res = GetString(key);
            if (res.Length == 0) return def;
            UInt64.TryParse(res, out def);
            return def;
        } 
        #endregion

		#region 获取DateTime类型配置信息值 +static DateTime GetDateTime(string key, DateTime def = default(DateTime))
        /// <summary>
        /// 获取DateTime类型配置信息值
        /// </summary>
        /// <remarks>
        ///  2013-11-23 14:27 Created By iceStone
        /// </remarks>
        /// <param name="key">设置键</param>
        /// <param name="def">缺省值</param>
        /// <returns>设置值</returns>
        public static DateTime GetDateTime(string key, DateTime def = default(DateTime))
        {
            var res = GetString(key);
            if (res.Length == 0) return def;
            DateTime.TryParse(res, out def);
            return def;
        } 
        #endregion

		#region 获取Guid类型配置信息值 +static Guid GetGuid(string key, Guid def = default(Guid))
        /// <summary>
        /// 获取Guid类型配置信息值
        /// </summary>
        /// <remarks>
        ///  2013-11-23 14:27 Created By iceStone
        /// </remarks>
        /// <param name="key">设置键</param>
        /// <param name="def">缺省值</param>
        /// <returns>设置值</returns>
        public static Guid GetGuid(string key, Guid def = default(Guid))
        {
            var res = GetString(key);
            if (res.Length == 0) return def;
            Guid.TryParse(res, out def);
            return def;
        } 
        #endregion

	}
}
